package com.carsa.blackberry.domain.dto;

import com.carsa.blackberry.util.XMLHandler;
import com.carsa.blackberry.util.XMLPortable;

public class SecondReasonDTO implements XMLPortable {

    private static final String XML_ELEMENT_DESCRIPT       = "descript";
    private static final String XML_ELEMENT_SUBREASON_CODE = "subreasonCode";
    private static final String XML_ELEMENT_FLEPA          = "flepa";
    private static final String XML_ELEMENT_REASON_CODE    = "reasonCode";

    private String              descript;
    private String              code;
    private String              flepa;
    private String              reasonCode;

    public SecondReasonDTO(String descript, String code, String flepa, String reasonCode) {
	super();
	this.descript = descript;
	this.code = code;
	this.flepa = flepa;
	this.reasonCode = reasonCode;
    }

    public SecondReasonDTO(String xmlSource) {
	this.initializeFromXML(xmlSource);
    }

    public boolean isFlepaSetted() {
	if (flepa == null)
	    return false;

	return !this.flepa.equals("");
    }

    public void initializeFromXML(String xmlSource) {
	XMLHandler xml = new XMLHandler(xmlSource);

	this.descript = xml.getElementValue(XML_ELEMENT_DESCRIPT);
	this.code = xml.getElementValue(XML_ELEMENT_SUBREASON_CODE);
	this.flepa = xml.getElementValue(XML_ELEMENT_FLEPA);
	this.reasonCode = xml.getElementValue(XML_ELEMENT_REASON_CODE);
    }

    public String toXMLString() {
	XMLHandler xml = new XMLHandler("aSecondReason", null, null);

	xml.addElementAtRoot(XML_ELEMENT_REASON_CODE, null, this.reasonCode);
	xml.addElementAtRoot(XML_ELEMENT_SUBREASON_CODE, null, this.code);
	xml.addElementAtRoot(XML_ELEMENT_DESCRIPT, null, this.descript);
	xml.addElementAtRoot(XML_ELEMENT_FLEPA, null, this.flepa);

	return xml.toXMLString();
    }

    public String toString() {
	return "SecondReasonDTO [  code=" + code + ",  descript=" + descript + ",  flepa=" + flepa + ",  reasonCode="
	        + reasonCode + "  ]";
    }

    /**
     * @return the descript
     */
    public String getDescript() {
	return descript;
    }

    /**
     * @param descript
     *            the descript to set
     */
    public void setDescript(String descript) {
	this.descript = descript;
    }

    /**
     * @return the code
     */
    public String getCode() {
	return code;
    }

    /**
     * @param code
     *            the code to set
     */
    public void setCode(String code) {
	this.code = code;
    }

    /**
     * @return the flepa
     */
    public String getFlepa() {
	return flepa;
    }

    /**
     * @param flepa
     *            the flepa to set
     */
    public void setFlepa(String flepa) {
	this.flepa = flepa;
    }

    /**
     * @return El codigo del motivo al cual pertenece este submotivo.
     */
    public String getReasonCode() {
	return this.reasonCode;
    }

}
